package plus.feifei.attack.bean;

import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import lombok.Data;

@Data
public class ApiRequestBean {
    private String name;
    private String url;
    private JSONObject header;
    private String method;
    private String contentType;
    private JSONObject body;
    private int cd;

    /**
     * 替换手机号
     *
     * @param phone
     */
    public void replacePhone(String phone) {
        if(StrUtil.contains(url,"${phone}")){
            url=url.replace("${phone}",phone);
        }
        if (StrUtil.equals(contentType, "json")) {
            if(body==null){
                return;
            }
            for (String key : body.keySet()) {
                if (StrUtil.equals(body.getStr(key), "${phone}")) {
                    body.put(key, phone);
                }
            }
        }
    }
}
